/*
 * @Author: your name
 * @Date: 2020-07-22 10:18:16
 * @LastEditTime: 2020-07-24 14:39:36
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \tinkjsDemo\src\config\middleware.js
 */ 
const path = require('path');
const historyFallback = require('koa2-history-api-fallback');
const isDev = think.env === 'development';

module.exports = [
  {
    handle: 'meta',
    options: {
      logRequest: isDev,
      sendResponseTime: isDev
    }
  },
  {
    handle: 'resource',
    enable: isDev,
    options: {
      root: path.join(think.ROOT_PATH, 'www'),
      publicPath: /^\/(static|dist|favicon\.ico)/
    }
  },
  // {
  //   handle: historyFallback,
  //   // enable: !isDev,
  //   match: ctx => {
  //       const excludeUrl = ['/index/downloadFile', '/index/viewBootPage','/kmlc/test/index'];//需要特殊处理的请求路径，如基于get方式的(href,download)
  //     if (!excludeUrl.includes(ctx.path)) {
  //       return true;

  //     }
  //     return false;
  //   }
  // },
  {
    handle: 'trace',
    enable: !think.isCli,
    options: {
      debug: isDev
    }
  },
  {
    handle: 'payload',
    options: {
      keepExtensions: true,
      limit: '5mb'
    }
  },
  {
    handle: 'router',
    options: {}
  },
  'logic',
  'controller'
];
